package org.adream.account.util;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON;


/**
 * restful接口的认证，使用AOP切入
 * 
 * @author sunset shen
 *
 */
public class RestfulAuthenticatFilter  implements Filter  {
	
	Logger logger = LoggerFactory.getLogger(this.getClass());
	
	private static long timeout;
	
	static {
		//读取配置文件中的配置项
		String accountRestfulTimeout = Utils.readProperty("config/info.properties", "account.restful.timeout");
		timeout = StringUtils.isEmpty(accountRestfulTimeout) ? Constant.ACCOUNT_RESTFUL_TIMEOUT_DEFAULT : Long.parseLong(accountRestfulTimeout);		
	}
	
	@Override
	public void destroy() {
		 
		
	}
	
 
	@Override
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain fc)
			throws IOException, ServletException {
		fc.doFilter(servletRequest, servletResponse);
	}
 
	@Override
	public void init(FilterConfig arg0) throws ServletException {
		
 	}
	
	private void errMsg(String errMsg,ServletResponse servletResponse) throws IOException {
		servletResponse.setContentType("application/json;charset=utf-8");
		PrintWriter pw = servletResponse.getWriter();
		pw.write("{\"returnCode\":9001,\"returnMsg\":\"");
		pw.write(errMsg);
		pw.write("\"}");
		pw.flush();
		pw.close();
	}
}

